include(CheckTypeSize)
include(TestBigEndian)

macro(CHECK_SYSTEM_PLATFORM _PLATFORM _ARCH _ENDIAN)
    message(STATUS "Operation System is ${CMAKE_SYSTEM}")
    
    # Platform detect
    if (CMAKE_SYSTEM_NAME MATCHES "Windows")
        set(${_PLATFORM} PLATFORM_WINDOWS)
        set(_WINDOWS TRUE)
    elseif (CMAKE_SYSTEM_NAME MATCHES "Linux")
        set(${_PLATFORM} PLATFORM_LINUX)
        set(_LINUX TRUE)
    elseif (CMAKE_SYSTEM_NAME MATCHES "Darwin")
        set(${_PLATFORM} PLATFORM_APPLE)
        set(_APPLE TRUE)
    endif()
    
    # Arch detect
    CHECK_TYPE_SIZE("void*" POINTER_SIZE)
    if (${POINTER_SIZE} MATCHES 8)
        set(${_ARCH} ARCH_X64)
        set(_x64 TRUE)
    else()
        set(${_ARCH} ARCH_X86)
        set(_x86 TRUE)
    endif()
    
    # Endian detect
    TEST_BIG_ENDIAN(BIG_ENDIAN)
    if (${BIG_ENDIAN})
        set(${_ENDIAN} ENDIAN_BIG)
    else()
        set(${_ENDIAN} ENDIAN_LITTLE)
    endif()
endmacro()
